<template>
  <div class="contact-container">
    <content-framework>
      <template #left>
        <div class="contact-left">
          <search :type="2"></search>
          <div class="contact-manager-container">
            <div class="contact-manager-content no-drag">
              <div>
                <span class="iconfont icon-lianxiren"  style="font-size: 18px;margin-right: 10px"></span>
                <span style="color: black">通讯录管理</span>
              </div>
            </div>
          </div>

          <el-collapse class="no-drag collapse" :expand-icon-position="'left'">
            <el-collapse-item  :name="index + 1" v-for="(item , index) in menuList">
              <template #title="{ isActive }">
                  <div @click="handleActive(isActive , item)" style="display: flex;justify-content: space-between">
                    <span>{{item.title}}</span>
                    <span style="color: rgb(177, 177, 177)">{{item.number ? item.number : ''}}</span>
                  </div>
              </template>
              <contact-list :type="item.type" :data="contactListContainer[item.title]"></contact-list>
            </el-collapse-item>


          </el-collapse>
        </div>

      </template>
      <template #right>

        <div class="contact-detail" v-if="contactStore.contactInfo">
          <user-info width="400px" :contactDetail="contactStore.contactInfo"></user-info>
        </div>
        <empty v-else></empty>
<!--          <detail style="width: 100%" :data="contractDetail"></detail>-->
      </template>
    </content-framework>
  </div>
</template>

<script setup>
import  empty from '@/components/empty/index.vue'
import userInfo from '@/components/user/info/index.vue'
import search from '@/components/search/index.vue'
import contentFramework from '@/framework/rightContent/index.vue'
import detail from '@/views/contact/detail/index.vue'
import contactList from '@/components/contactList/index.vue'
import { ref } from 'vue'
import { getUserApplyList } from '@/api/user'
import { useUserStore } from '@/stores/user'
import { useContactStore } from '../../stores/contact'


const contactStore = useContactStore()
const contactListContainer = ref({})
const userStore = useUserStore()

const menuList = ref(
  [
    { title: '新的朋友', type: 2 , number: 20 },
    { title: '公众号', type: 6 , number: 0 },
    { title: '服务号' , type: 5, number: 0},
    { title: '企业微信联系人' , type: 4, number: 0},
    { title: '我的企业' , type: 3, number: 1},
    { title: '联系人' , type: 1, number: 1},
  ]
)



menuList.value.forEach((item, index) => {
  contactListContainer.value[item.title] = []
})

const contractDetail = ref(null)

// 点击选项时
const handleActive = async  (isActive , menu) => {

  const type = menu.type
  // 由关闭 -> 打开时查一下
  if (!isActive) {
    let res = {}
    switch (type) {
      case 2 : res = await getUserApplyList(userStore.uid);break;
    }


    if (res.code === 200) {
      contactListContainer.value[menu.title] = res.data
    }

    console.log(contactListContainer.value)


  }




}

</script>


<style scoped lang="less">

.contact-container {
  height: 100%;
  width: 100%;


  .contact-left {
    background-color: rgb(247, 247, 247);
    height: 100%;

    .contact-manager-container {
      width: 100%;
      height: 35px;
      padding: 0 10px;
      box-sizing: border-box;

      .contact-manager-content {
        cursor: pointer;
        background-color: white;
        height: 100%;
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
      }

    }

    .collapse {
      background-color: rgb(247, 247, 247) !important;
      //padding: 0 10px ;
      border: none;
      user-select: none;


      :deep(.el-collapse-item__header){
        height: 40px;
        padding: 0 10px;
      }

      :deep(.el-collapse-item__header)
      ,
      :deep(.el-collapse-item__wrap)
      {
        background-color: rgb(247, 247, 247) !important;
        border: none;
        gap: 5px !important;
      }

      :deep(.el-collapse-item__arrow) {
        font-size: 18px;
        font-weight: bolder;
      }
      :deep(.el-collapse-item__content) {
        padding-bottom: 0px !important;
      }

    }

  }

  .contact-detail {
    padding-top: 40px;
    display: flex;
    justify-content: center;
  }


}

</style>
